using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace edu.stanford.hci.ideas
{
    /// <summary>
    /// Summary description for TransPanel.
    /// </summary>
    public class TransPanel : Panel
    {
        bool brighten = false;
        bool dim = false;
        bool toggle = false;

        public TransPanel()
        {
            this.SetStyle(
                ControlStyles.OptimizedDoubleBuffer, true);
        }

        public void setBrighten()
        {
            Console.WriteLine("setBrighten");
            brighten = true;
            dim = false;
            //Invalidate();
        }
        public void setDim()
        {
            dim = true;
            brighten = false;
            //Invalidate();
        }

        public void setToggle()
        {
            Console.WriteLine("setToggle");
            toggle = true;
            Invalidate();
        }
       
        
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
                return cp;
            }
        }


       
        protected void InvalidateEx()
        {

            if (Parent == null)

               return;



            Rectangle rc = new Rectangle(this.Location, this.Size);

            Parent.Invalidate(rc, true);

        }

       
        
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {

            //do not allow the background to be painted 

        }
        
        public void UpdateVisibility()
        {
            if (brighten)
            {
                Brighten();
                brighten = false;
            }
            else if (dim)
            {
                Dim();
                dim = false;
            }
            else if (toggle)
            {
                Toggle();
                toggle = false;
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.Visible)
            {

                Console.WriteLine("OnPaint" + this.Visible);
                Rectangle rect = new Rectangle(0, 0, this.Size.Width, this.Size.Height);
                SolidBrush colorBrush = new SolidBrush(Color.FromArgb(50, Color.DarkGray));
                e.Graphics.FillRectangle(colorBrush, rect);
                colorBrush.Dispose();
            }
        }


        public void Toggle()
        {
            Console.WriteLine("Toggle");
            if (this.Visible)
                this.Hide();
       
            //else this.Show();
        }

        public void Dim()
        {
            if (!this.Visible)
            {
               //this.Show();
            }
        }
        public void Brighten()
        {
            Console.WriteLine("Brighten");
            if (!this.Visible)
            {
                return;
            }
            this.Hide();
            if (this.Visible)
            {
                Console.WriteLine("WHAT?!?!?");
            }
            //this.SetBounds(0, 0, 0, 0);
        }
    }

}